package chapter05;

import java.lang.reflect.Array;
import java.util.Arrays;

public class Test02_String1 {
    public static void main(String[] args) {
        //字符串的替换
        String s = "我是一名学生";
        String s1 = s.replace("学生","老师");
        System.out.println(s1);
        System.out.println(s);
        //去除首尾空格
        String s2 = "  username  ";
        System.out.println(s2.trim());
        String s3 = "     ";
        System.out.println(s3.trim());
        //判断字符串的开头
        String s4 = "String";
        System.out.println(s4.startsWith("St"));
        System.out.println(s4.endsWith("ng"));
        System.out.println(s4.contains("ri"));
        System.out.println(s4.isEmpty());
        String s5 = "   ";//只有在字符串中没有内容的时候才是真
        System.out.println(s5.isEmpty());
        String s6 = "string";//字符串的字面值相等判断使用equals
        System.out.println(s4.equals(s6));
        System.out.println(s4.equalsIgnoreCase(s6));
        String s7 = new String("string");
        //==比较的其实是指针 指向了不同对象
        System.out.println(s6==s7);
        System.out.println(s6.equals(s7));
        //字符串的截取
        String s8 = "北京-秦皇岛-哈尔滨";
        System.out.println(s8.substring(2));
        System.out.println(s8.substring(2,6));
        System.out.println((Arrays.toString(s8.split("-"))));
        //统计字符串中字符出现的次数 abcdadfkjla(选做)
        //将字符串翻转 abc->cba
        //将单词翻转 i am a student -> student a am i
    }
}
